package cn.zhaoyuening.chat_server.container.impl;

import cn.zhaoyuening.chat_server.container.ChannelContainer;
import io.netty.channel.Channel;

import java.util.Collection;
import java.util.HashMap;
import java.util.Set;

/**
 * Created by Buynow on 2017/6/14.
 */
public class BaseChannelContainer implements ChannelContainer {
    private HashMap<String,Channel> channelMap;

    public BaseChannelContainer() {
        channelMap = new HashMap<>();
    }

    @Override
    public Channel get(String channelId) {
        Channel channel = channelMap.get(channelId);
        return channel;
    }

    @Override
    public void remove(String channelId) {
        channelMap.remove(channelId);
    }

    @Override
    public void remove(Channel channel) {
        String channelId = channel.id().asLongText();
        remove(channelId);
    }

    @Override
    public String add(Channel channel) {
        String channelId = channel.id().asLongText();
        channelMap.put(channelId, channel);
        return channelId;
    }

    @Override
    public Collection<Channel> allChannel() {
        return channelMap.values();
    }

    @Override
    public Set<String> allChannelId() {
        return channelMap.keySet();
    }


}
